<?php

if($_POST['submit'])
{
  if(   (($_FILES["file"]["type"]== "image/gif")||($_FILES["file"]["type"]== "image/png")||
         ($_FILES["file"]["type"]== "image/jpeg")||($_FILES["file"]["type"]== "image/pjpeg"))&&($_FILES["file"]["size"] < 262144)   )
  {
      if ($_FILES["file"]["error"] > 0) // the error code resulting from the file upload
      {
      	echo "Error: " . $_FILES["file"]["error"] . "<br />";
      }
  	  else
      {
		  $target_path = "/home/a7184847/public_html/g_pic/pic/";
		  $target_path = $target_path.basename( $_FILES['file']['name'] );

	  	  echo "Nazwa: <b>" . $_FILES["file"]["name"] . "</b><br />"; // the name of the uploaded file
    	  echo "Typ: <b>" . $_FILES["file"]["type"] . "</b><br />";   // the type of the uploaded file
	  	  echo "Rozmiar: <b>" . ($_FILES["file"]["size"] / 1024) . " Kb</b><br />"; // the size in bytes of the uploaded file
		  // echo "Zapisano w tymczasowej kopii: <b>" . $_FILES["file"]["tmp_name"] . "</b><br>"; the name of the temporary copy of the file stored on the server
		  if (file_exists($target_path))
      	  {
	      	echo "<span style=\"color: #C00; font-weight: bold;\">". $_FILES["file"]["name"] . " - Taki plik istnieje </span><br>";
      	  }
    	  else
      	  {
      	  	move_uploaded_file($_FILES["file"]["tmp_name"], $target_path);
      		echo "Zapisano w: <b>" . $target_path . "</b><br>";
/************************************************************** zanzaczenie obrazka w bazie *********************************************************************/
			  $data = date("Y-m-d H:i:s");
			  $link = "http://rus.warmia.pl/g_pic/pic/". $_FILES["file"]["name"];
			  $opis = $_POST['opis'];
			  $group = $_POST['id'];
			  include('minipic.php'); //tworzenie miniaturek////////////////////////////////////////////////////////////////////////////
  			  $link_m = "http://rus.warmia.pl/g_pic/m_pic/"."m_".$_FILES["file"]["name"];

	  		$query="INSERT INTO GALERIA (`LINK`, `LINK_M`, `OPIS`, `GROUP`, `DATE`)VALUES ('".$link."', '".$link_m."', '".$opis."', '".$group."', '".$data."');";
	        mysql_query($query) or die(mysql_error());
/****************************************************************************************************************************************************************/
      	  }
      }
  }
  else
  {
      echo "<b>Niewłaściwy plik</b><br>";
  }
}
?>
	<form action="/?content=editgal" method="post" enctype="multipart/form-data">
		<label for="file">Wybierz lokalizacje pliku:</label><br>
		<input type="file" name="file" id="file" /><br>
        <label for="file">Opis do zdjęcia (gdy obrazek ma mieć opis to wypełnij poniższe pole przed kliknięciem "wyślij"):</label><br>
        <textarea name="opis"style="font-size: 10pt; font-family: Tahoma; width: 380px; height: 100px;"></textarea><br>
        <input type="hidden" name="id" value="<?php echo $_GET['id']; ?>" />
   		<input type="submit" name="submit" value="Wyślij" /><br>
	</form>